<template>
  <el-dialog
    :title="!houses.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="houses" :rules="dataRule" ref="houses" @keyup.enter.native="housesSubmit()" label-width="80px">
    <el-form-item label="楼盘名称" prop="housesName">
      <el-input v-model="houses.housesName" placeholder="楼盘名称"></el-input>
    </el-form-item>
    <el-form-item label="省份id" prop="provinceId">
      <el-input v-model="houses.provinceId" placeholder="省份id"></el-input>
    </el-form-item>
    <el-form-item label="市级id" prop="cityId">
      <el-input v-model="houses.cityId" placeholder="市级id"></el-input>
    </el-form-item>
    <el-form-item label="楼盘地址" prop="addr">
      <el-input v-model="houses.addr" placeholder="楼盘地址"></el-input>
    </el-form-item>
    <el-form-item label="开盘时间" prop="openingTime">
      <el-input v-model="houses.openingTime" placeholder="开盘时间"></el-input>
    </el-form-item>
    <el-form-item label="开盘状态" prop="openingStatus">
      <el-input v-model="houses.openingStatus" placeholder="开盘状态"></el-input>
    </el-form-item>
    <el-form-item label="已开盘描述" prop="openingDesc">
      <el-input v-model="houses.openingDesc" placeholder="已开盘描述"></el-input>
    </el-form-item>
    <el-form-item label="售楼电话" prop="sellHouseTel">
      <el-input v-model="houses.sellHouseTel" placeholder="售楼电话"></el-input>
    </el-form-item>
    <el-form-item label="开发商" prop="developers">
      <el-input v-model="houses.developers" placeholder="开发商"></el-input>
    </el-form-item>
    <el-form-item label="均价" prop="averagePrice">
      <el-input v-model="houses.averagePrice" placeholder="均价"></el-input>
    </el-form-item>
    <el-form-item label="单位" prop="priceUnit">
      <el-input v-model="houses.priceUnit" placeholder="单位"></el-input>
    </el-form-item>
    <el-form-item label="单位描述" prop="priceUnitName">
      <el-input v-model="houses.priceUnitName" placeholder="单位描述"></el-input>
    </el-form-item>
    <el-form-item label="售楼处地址" prop="salesOfficeAddr">
      <el-input v-model="houses.salesOfficeAddr" placeholder="售楼处地址"></el-input>
    </el-form-item>
    <el-form-item label="交房时间" prop="checkOutDate">
      <el-input v-model="houses.checkOutDate" placeholder="交房时间"></el-input>
    </el-form-item>
    <el-form-item label="交房状态" prop="checkOutStatus">
      <el-input v-model="houses.checkOutStatus" placeholder="交房状态"></el-input>
    </el-form-item>
    <el-form-item label="已交房" prop="checkOutDesc">
      <el-input v-model="houses.checkOutDesc" placeholder="已交房"></el-input>
    </el-form-item>
    <el-form-item label="预售证号" prop="presellNumber">
      <el-input v-model="houses.presellNumber" placeholder="预售证号"></el-input>
    </el-form-item>
    <el-form-item label="地图坐标" prop="mapCoordinate">
      <el-input v-model="houses.mapCoordinate" placeholder="地图坐标"></el-input>
    </el-form-item>
    <el-form-item label="购房红包" prop="redPacket">
      <el-input v-model="houses.redPacket" placeholder="购房红包"></el-input>
    </el-form-item>
    <el-form-item label="优惠楼盘" prop="preferentialStatus">
      <el-input v-model="houses.preferentialStatus" placeholder="优惠楼盘"></el-input>
    </el-form-item>
    <el-form-item label="装修情况id" prop="decorateSituationId">
      <el-input v-model="houses.decorateSituationId" placeholder="装修情况id"></el-input>
    </el-form-item>
    <el-form-item label="装修情况" prop="decorateSituationName">
      <el-input v-model="houses.decorateSituationName" placeholder="装修情况"></el-input>
    </el-form-item>
    <el-form-item label="销售状态id" prop="marketStatusId">
      <el-input v-model="houses.marketStatusId" placeholder="销售状态id"></el-input>
    </el-form-item>
    <el-form-item label="销售状态" prop="marketStatus">
      <el-input v-model="houses.marketStatus" placeholder="销售状态"></el-input>
    </el-form-item>
    <el-form-item label="楼盘类型id" prop="housesTypeId">
      <el-input v-model="houses.housesTypeId" placeholder="楼盘类型id"></el-input>
    </el-form-item>
    <el-form-item label="楼盘类型" prop="housesType">
      <el-input v-model="houses.housesType" placeholder="楼盘类型"></el-input>
    </el-form-item>
    <el-form-item label="特色标签id" prop="specialLabelId">
      <el-input v-model="houses.specialLabelId" placeholder="特色标签id"></el-input>
    </el-form-item>
    <el-form-item label="特色标签" prop="specialLabel">
      <el-input v-model="houses.specialLabel" placeholder="特色标签"></el-input>
    </el-form-item>
    <el-form-item label="推荐id" prop="recommendId">
      <el-input v-model="houses.recommendId" placeholder="推荐id"></el-input>
    </el-form-item>
    <el-form-item label="推荐" prop="recommendName">
      <el-input v-model="houses.recommendName" placeholder="推荐"></el-input>
    </el-form-item>
    <el-form-item label="缩略图" prop="image">
      <el-input v-model="houses.image" placeholder="缩略图"></el-input>
    </el-form-item>
    <el-form-item label="看房视频" prop="video">
      <el-input v-model="houses.video" placeholder="看房视频"></el-input>
    </el-form-item>
    <el-form-item label="全景看房" prop="panoramaLookHouses">
      <el-input v-model="houses.panoramaLookHouses" placeholder="全景看房"></el-input>
    </el-form-item>
    <el-form-item label="楼盘介绍" prop="housesRecommend">
      <el-input v-model="houses.housesRecommend" placeholder="楼盘介绍"></el-input>
    </el-form-item>
    <el-form-item label="建筑类型" prop="architectureType">
      <el-input v-model="houses.architectureType" placeholder="建筑类型"></el-input>
    </el-form-item>
    <el-form-item label="占地面积" prop="floorSpace">
      <el-input v-model="houses.floorSpace" placeholder="占地面积"></el-input>
    </el-form-item>
    <el-form-item label="容积率" prop="plotRatio">
      <el-input v-model="houses.plotRatio" placeholder="容积率"></el-input>
    </el-form-item>
    <el-form-item label="户型规划" prop="households">
      <el-input v-model="houses.households" placeholder="户型规划"></el-input>
    </el-form-item>
    <el-form-item label="物业类型" prop="propertyType">
      <el-input v-model="houses.propertyType" placeholder="物业类型"></el-input>
    </el-form-item>
    <el-form-item label="物业费" prop="propertyFee">
      <el-input v-model="houses.propertyFee" placeholder="物业费"></el-input>
    </el-form-item>
    <el-form-item label="产权年限" prop="propertyRightAgeLimit">
      <el-input v-model="houses.propertyRightAgeLimit" placeholder="产权年限"></el-input>
    </el-form-item>
    <el-form-item label="建筑面积" prop="coveredArea">
      <el-input v-model="houses.coveredArea" placeholder="建筑面积"></el-input>
    </el-form-item>
    <el-form-item label="绿化率" prop="greeningRate">
      <el-input v-model="houses.greeningRate" placeholder="绿化率"></el-input>
    </el-form-item>
    <el-form-item label="车位情况" prop="parkingSituation">
      <el-input v-model="houses.parkingSituation" placeholder="车位情况"></el-input>
    </el-form-item>
    <el-form-item label="物业公司" prop="propertyManagementCompany">
      <el-input v-model="houses.propertyManagementCompany" placeholder="物业公司"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="housesSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        houses: {
          id: 0,
          housesName: '',
          provinceId: '',
          cityId: '',
          addr: '',
          openingTime: '',
          openingStatus: '',
          openingDesc: '',
          sellHouseTel: '',
          developers: '',
          averagePrice: '',
          priceUnit: '',
          priceUnitName: '',
          salesOfficeAddr: '',
          checkOutDate: '',
          checkOutStatus: '',
          checkOutDesc: '',
          presellNumber: '',
          mapCoordinate: '',
          redPacket: '',
          preferentialStatus: '',
          decorateSituationId: '',
          decorateSituationName: '',
          marketStatusId: '',
          marketStatus: '',
          housesTypeId: '',
          housesType: '',
          specialLabelId: '',
          specialLabel: '',
          recommendId: '',
          recommendName: '',
          image: '',
          video: '',
          panoramaLookHouses: '',
          housesRecommend: '',
          architectureType: '',
          floorSpace: '',
          plotRatio: '',
          households: '',
          propertyType: '',
          propertyFee: '',
          propertyRightAgeLimit: '',
          coveredArea: '',
          greeningRate: '',
          parkingSituation: '',
          propertyManagementCompany: ''
        },
        dataRule: {
          housesName: [
            { required: true, message: '楼盘名称不能为空', trigger: 'blur' }
          ],
          provinceId: [
            { required: true, message: '省份id不能为空', trigger: 'blur' }
          ],
          cityId: [
            { required: true, message: '市级id不能为空', trigger: 'blur' }
          ],
          addr: [
            { required: true, message: '楼盘地址不能为空', trigger: 'blur' }
          ],
          openingTime: [
            { required: true, message: '开盘时间不能为空', trigger: 'blur' }
          ],
          openingStatus: [
            { required: true, message: '开盘状态不能为空', trigger: 'blur' }
          ],
          openingDesc: [
            { required: true, message: '已开盘描述不能为空', trigger: 'blur' }
          ],
          sellHouseTel: [
            { required: true, message: '售楼电话不能为空', trigger: 'blur' }
          ],
          developers: [
            { required: true, message: '开发商不能为空', trigger: 'blur' }
          ],
          averagePrice: [
            { required: true, message: '均价不能为空', trigger: 'blur' }
          ],
          priceUnit: [
            { required: true, message: '单位不能为空', trigger: 'blur' }
          ],
          priceUnitName: [
            { required: true, message: '单位描述不能为空', trigger: 'blur' }
          ],
          salesOfficeAddr: [
            { required: true, message: '售楼处地址不能为空', trigger: 'blur' }
          ],
          checkOutDate: [
            { required: true, message: '交房时间不能为空', trigger: 'blur' }
          ],
          checkOutStatus: [
            { required: true, message: '交房状态不能为空', trigger: 'blur' }
          ],
          checkOutDesc: [
            { required: true, message: '已交房不能为空', trigger: 'blur' }
          ],
          presellNumber: [
            { required: true, message: '预售证号不能为空', trigger: 'blur' }
          ],
          mapCoordinate: [
            { required: true, message: '地图坐标不能为空', trigger: 'blur' }
          ],
          redPacket: [
            { required: true, message: '购房红包不能为空', trigger: 'blur' }
          ],
          preferentialStatus: [
            { required: true, message: '优惠楼盘不能为空', trigger: 'blur' }
          ],
          decorateSituationId: [
            { required: true, message: '装修情况id不能为空', trigger: 'blur' }
          ],
          decorateSituationName: [
            { required: true, message: '装修情况不能为空', trigger: 'blur' }
          ],
          marketStatusId: [
            { required: true, message: '销售状态id不能为空', trigger: 'blur' }
          ],
          marketStatus: [
            { required: true, message: '销售状态不能为空', trigger: 'blur' }
          ],
          housesTypeId: [
            { required: true, message: '楼盘类型id不能为空', trigger: 'blur' }
          ],
          housesType: [
            { required: true, message: '楼盘类型不能为空', trigger: 'blur' }
          ],
          specialLabelId: [
            { required: true, message: '特色标签id不能为空', trigger: 'blur' }
          ],
          specialLabel: [
            { required: true, message: '特色标签不能为空', trigger: 'blur' }
          ],
          recommendId: [
            { required: true, message: '推荐id不能为空', trigger: 'blur' }
          ],
          recommendName: [
            { required: true, message: '推荐不能为空', trigger: 'blur' }
          ],
          image: [
            { required: true, message: '缩略图不能为空', trigger: 'blur' }
          ],
          video: [
            { required: true, message: '看房视频不能为空', trigger: 'blur' }
          ],
          panoramaLookHouses: [
            { required: true, message: '全景看房不能为空', trigger: 'blur' }
          ],
          housesRecommend: [
            { required: true, message: '楼盘介绍不能为空', trigger: 'blur' }
          ],
          architectureType: [
            { required: true, message: '建筑类型不能为空', trigger: 'blur' }
          ],
          floorSpace: [
            { required: true, message: '占地面积不能为空', trigger: 'blur' }
          ],
          plotRatio: [
            { required: true, message: '容积率不能为空', trigger: 'blur' }
          ],
          households: [
            { required: true, message: '户型规划不能为空', trigger: 'blur' }
          ],
          propertyType: [
            { required: true, message: '物业类型不能为空', trigger: 'blur' }
          ],
          propertyFee: [
            { required: true, message: '物业费不能为空', trigger: 'blur' }
          ],
          propertyRightAgeLimit: [
            { required: true, message: '产权年限不能为空', trigger: 'blur' }
          ],
          coveredArea: [
            { required: true, message: '建筑面积不能为空', trigger: 'blur' }
          ],
          greeningRate: [
            { required: true, message: '绿化率不能为空', trigger: 'blur' }
          ],
          parkingSituation: [
            { required: true, message: '车位情况不能为空', trigger: 'blur' }
          ],
          propertyManagementCompany: [
            { required: true, message: '物业公司不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.houses.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['houses'].resetFields()
          if (this.houses.id) {
            this.$http({
              url: this.$http.adornUrl(`/broker/houses/info/${this.houses.id}`),
              method: 'get',
              params: this.$http.ador9
              if (data && data.code === 0) {
                this.houses.housesName = data.houses.housesName
                this.houses.provinceId = data.houses.provinceId
                this.houses.cityId = data.houses.cityId
                this.houses.addr = data.houses.addr
                this.houses.openingTime = data.houses.openingTime
                this.houses.openingStatus = data.houses.openingStatus
                this.houses.openingDesc = data.houses.openingDesc6
                this.houses.sellHouseTel = data.houses.sellHouseTel
                this.houses.developers = data.houses.developers
                this.houses.averagePrice = data.houses.averagePrice
                this.houses.priceUnit = data.houses.priceUnit
                this.houses.priceUnitName = data.houses.priceUnitName
                this.houses.salesOfficeAddr = data.houses.salesOfficeAddr
                this.houses.checkOutDate = data.houses.checkOutDate
                this.houses.checkOutStatus = data.houses.checkOutStatus
                this.houses.checkOutDesc = data.houses.checkOutDesc
                this.houses.presellNumber = data.houses.presellNumber
                this.houses.mapCoordinate = data.houses.mapCoordinate
                this.houses.redPacket = data.houses.redPacket
                this.houses.preferentialStatus = data.houses.preferentialStatus
                this.houses.decorateSituationId = data.houses.decorateSituationId
                this.houses.decorateSituationName = data.houses.decorateSituationName
                this.houses.marketStatusId = data.houses.marketStatusId
                this.houses.marketStatus = data.houses.marketStatus
                this.houses.housesTypeId = data.houses.housesTypeId
                this.houses.housesType = data.houses.housesType
                this.houses.specialLabelId = data.houses.specialLabelId
                this.houses.specialLabel = data.houses.specialLabel
                this.houses.recommendId = data.houses.recommendId
                this.houses.recommendName = data.houses.recommendName
                this.houses.image = data.houses.image
                this.houses.video = data.houses.video
                this.houses.panoramaLookHouses = data.houses.panoramaLookHouses
                this.houses.housesRecommend = data.houses.housesRecommend
                this.houses.architectureType = data.houses.architectureType
                this.houses.floorSpace = data.houses.floorSpace
                this.houses.plotRatio = data.houses.plotRatio
                this.houses.households = data.houses.households
                this.houses.propertyType = data.houses.propertyType
                this.houses.propertyFee = data.houses.propertyFee
                this.houses.propertyRightAgeLimit = data.houses.propertyRightAgeLimit
                this.houses.coveredArea = data.houses.coveredArea
                this.houses.greeningRate = data.houses.greeningRate
                this.houses.parkingSituation = data.houses.parkingSituation
                this.houses.propertyManagementCompany = data.houses.propertyManagementCompany
              }
            })
          }
        })
      },
      // 表单提交
      housesSubmit () {
        this.$refs['houses'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/broker/houses/${!this.houses.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.houses.id || undefined,
                'housesName': this.houses.housesName,
                'provinceId': this.houses.provinceId,
                'cityId': this.houses.cityId,
                'addr': this.houses.addr,
                'openingTime': this.houses.openingTime,
                'openingStatus': this.houses.openingStatus,
                'openingDesc': this.houses.openingDesc,
                'sellHouseTel': this.houses.sellHouseTel,
                'developers': this.houses.developers,
                'averagePrice': this.houses.averagePrice,
                'priceUnit': this.houses.priceUnit,
                'priceUnitName': this.houses.priceUnitName,
                'salesOfficeAddr': this.houses.salesOfficeAddr,
                'checkOutDate': this.houses.checkOutDate,
                'checkOutStatus': this.houses.checkOutStatus,
                'checkOutDesc': this.houses.checkOutDesc,
                'presellNumber': this.houses.presellNumber,
                'mapCoordinate': this.houses.mapCoordinate,
                'redPacket': this.houses.redPacket,
                'preferentialStatus': this.houses.preferentialStatus,
                'decorateSituationId': this.houses.decorateSituationId,
                'decorateSituationName': this.houses.decorateSituationName,
                'marketStatusId': this.houses.marketStatusId,
                'marketStatus': this.houses.marketStatus,
                'housesTypeId': this.houses.housesTypeId,
                'housesType': this.houses.housesType,
                'specialLabelId': this.houses.specialLabelId,
                'specialLabel': this.houses.specialLabel,
                'recommendId': this.houses.recommendId,
                'recommendName': this.houses.recommendName,
                'image': this.houses.image,
                'video': this.houses.video,
                'panoramaLookHouses': this.houses.panoramaLookHouses,
                'housesRecommend': this.houses.housesRecommend,
                'architectureType': this.houses.architectureType,
                'floorSpace': this.houses.floorSpace,
                'plotRatio': this.houses.plotRatio,
                'households': this.houses.households,
                'propertyType': this.houses.propertyType,
                'propertyFee': this.houses.propertyFee,
                'propertyRightAgeLimit': this.houses.propertyRightAgeLimit,
                'coveredArea': this.houses.coveredArea,
                'greeningRate': this.houses.greeningRate,
                'parkingSituation': this.houses.parkingSituation,
                'propertyManagementCompany': this.houses.propertyManagementCompany
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
